﻿using System;
using VideoServices.Domain.DAL;
using VideoServices.Domain.Entities;

namespace VideoServices.Business
{
    public class WarehouseBusinessObject
    {
        #region Fields

        private readonly IWarehouseDataAccess warehouseDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="WarehouseBusinessObject"/> class.
        /// </summary>
        public WarehouseBusinessObject()
        {
            warehouseDao = new WarehouseDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="WarehouseBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public WarehouseBusinessObject(IWarehouseDataAccess dao)
        {
            // This constructor enables easy TDD as it takes in whatever IOrderDataAccess implementation.
            warehouseDao = dao;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets the warehouse by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Warehouse GetWarehouseById(int id)
        {
            Warehouse warehouse;
            try
            {
                warehouse = warehouseDao.GetWarehouseById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return warehouse;
        }

        /// <summary>
        /// Creates the warehouse.
        /// </summary>
        /// <param name="newWarehouse">The new warehouse.</param>
        /// <returns></returns>
        public Warehouse CreateWarehouse(Warehouse newWarehouse)
        {
            Warehouse warehouse;
            try
            {
                warehouse = warehouseDao.CreateWarehouse(newWarehouse);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return warehouse;
        }

        #endregion
    }
}
